package com.liyk.shop.response;

import com.liyk.shop.enums.ResponseStatusEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private Integer code;

    private String msg;

    private Object data;

    public static Result success(Object data){
        return custom(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), data);
    }

    public static Result success(){
        return custom(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), null);
    }

    public static Result serverException(Object data){
        return custom(ResponseStatusEnum.SERVER_EXCEPTION.getCode(), ResponseStatusEnum.SERVER_EXCEPTION.getMsg(), data);
    }

    public static Result fail(Integer code,String msg){
        return custom(code, msg, null);
    }

    public static Result custom(Integer code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}
